package cn.tedu.csmall.passportbackup.controller;

import cn.tedu.csmall.passportbackup.pojo.dto.AdminAddNewDTO;
import cn.tedu.csmall.passportbackup.pojo.dto.AdminLoginDTO;
import cn.tedu.csmall.passportbackup.servic.IAdminService;
import cn.tedu.csmall.passportbackup.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import sun.security.timestamp.TSRequest;

import javax.validation.Valid;

@Slf4j
@Api(tags = "01用户管理模块")
@RequestMapping("/admins")
@RestController
public class AdminController {

    public AdminController() {
        log.debug("开始创建AdminController控制器");
    }

    @Autowired
    private IAdminService adminService;


    @ApiOperationSupport(order = 100)
    @ApiOperation("添加管理员")
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(@Valid AdminAddNewDTO adminAddNewDTO){
        log.debug("开始处理【添加管理员】的请求");
        adminService.addNew(adminAddNewDTO);
        return JsonResult.ok();
    }


    @ApiOperation("管理员登录")
    @ApiOperationSupport(order = 400)
    @PostMapping("/login")
    public JsonResult<String> login(AdminLoginDTO adminLoginDTO){
        log.debug("开始处理【管理员登录】的业务");
        String jwt = adminService.login(adminLoginDTO);
        return JsonResult.ok(jwt);
    }
}
